//修改模板
import React, {Component} from 'react';
import {Button, Form, Input, Row, Col, Modal, Icon, Tag} from 'antd';
import app from '../AppMethod';
import {employee, takeOutput} from '../value';

const FormItem = Form.Item;

//选择操作人
class ChooseOperate extends Component {
    constructor(props) {
        super(props);
        this.state = {
            editVisible: false,
            editConfirmLoading: false,
            roleData: [],
            type: this.props.type,
            chooseData: {},
            is_choose: -1,
            currentPrinterId:'',
            editVisible1: false,
            editConfirmLoading1: false,
            printerData:[]
        }
    };

    render() {
        return (
            <span>
                <Button style={{marginLeft: this.props.left}} type={'primary'}
                        onClick={() => this.setModalVisible(true)}>{this.props.buttonText}</Button>
                <span>
                    <Modal
                        maskClosable={true}
                        visible={this.state.editVisible}
                        editConfirmLoading={this.state.editConfirmLoading}
                        title="选择员工"
                        wrapClassName="vertical-center-modal"
                        width="600px"
                        onCancel={() => this.setModalVisible(false)}
                        footer={[
                            <Button key="back" type='default' onClick={() => {
                                this.setModalVisible(false)
                            }}>取消</Button>,
                            <Button key="submit" type="primary" onClick={() => {
                                this.clickOk()
                            }}>确定</Button>
                        ]}
                    >
                    <div className="clearfix">
                        {
                            this.state.roleData.map((item, index) => {
                                return (
                                    <span key={index}
                                          className={this.state.is_choose == index ? "roleItem1" : "roleItem"}
                                          onClick={() => this.chooseRole(index)}>
                                        {item.employee_name}
                                    </span>
                                )
                            })
                        }
                    </div>
                </Modal>

                    <Modal
                        maskClosable={true}
                        visible={this.state.editVisible1}
                        editConfirmLoading={this.state.editConfirmLoading1}
                        title="选择打印机"
                        wrapClassName="vertical-center-modal"
                        width="600px"
                        onCancel={() => this.setModalVisible1(false)}
                        footer={[
                            <Button key="back" type='default' onClick={() => {
                                this.setModalVisible1(false)
                            }}>取消</Button>,
                            <Button key="submit" type="primary" onClick={() => {
                                this.clickPrinterOk()
                            }}>确定</Button>
                        ]}
                    >
                    <div className="clearfix">
                        {
                            this.state.printerData.map((item, index) => {
                                return (
                                    <span key={index}
                                          className={item.printer_id == this.state.currentPrinterId ? "roleItem1" : "roleItem"}
                                          onClick={() => this.choosePrinter(index)}>
                                        {item.printer_name}
                                    </span>
                                )
                            })
                        }
                    </div>
                </Modal>

                </span>
            </span>
        )
    };

    componentDidMount(){
        let currentPrinterId='';
        let type=this.props.type;
        if(type==1){//待接单打印机ip
            currentPrinterId=app.getData('printerOrderTaking');
        }else if(type==2){//我来配货打印机ip
            currentPrinterId=app.getData('printerDistribution');
        }else if(type==3){//我来对货打印机ip
            currentPrinterId=app.getData('printerCheckOrder');
        }
        if(!currentPrinterId){
            currentPrinterId='';
        }
        this.setState({currentPrinterId:currentPrinterId});
        app.post(takeOutput.SEARCH_PRINTERLIST, {page: 1, size: 1000}).then((result) => {
            if (result.code === 1) {
                let printerData = result.data.dataSet;
                this.setState({printerData: printerData});
            } else {
                app.alert(result.msg, 'error', 3);
                this.setState({printerData: []});
            }
        });
    };

    /**
     * 显示和隐藏负责人弹框
     * @param visible
     */
    setModalVisible(visible) {
        if (visible) {
            app.post(employee.SEARCH_DUTYEMPLOYEE, {duty_type: this.props.duty_type}).then((result) => {
                if (result.code === 1) {
                    let roleData = result.data.dataSet;
                    this.setState({roleData});
                } else {
                    app.alert('没有查询到负责人数据', 'error', 2);
                    this.setState({roleData: []});
                }
            })
        }
        this.setState({
            editVisible: visible
        })
    };

    /**
     * 显示和隐藏打印机弹框
     * @param visible
     */
    setModalVisible1(visible){
        this.setState({editVisible1:visible});
    };

    /**
     * 处理选择员工事件
     * @param index
     */
    chooseRole(index) {
        this.setState({is_choose: index});
        let chooseData = this.state.roleData[index];
        this.setState({chooseData: chooseData});
    };

    /**
     * 处理员工选择框确认事件
     */
    clickOk() {
        let data = this.state.chooseData;
        let employee_id = data.employee_id;
        if (employee_id == null || employee_id == undefined || employee_id.length <= 0) {
            app.alert("请选择操作人", 'error', 3);
            return;
        }
        this.setModalVisible1(true);
        this.setModalVisible(false);
    };

    /**
     * 处理选择打印机事件
     * @param index
     */
    choosePrinter(index){
        let data = this.state.printerData;
        let currentPrinterId = data[index].printer_id;
        this.setState({currentPrinterId: currentPrinterId});
    };

    /**
     * 处理打印机弹框确认事件
     */
    clickPrinterOk(){
        let currentPrinterId=this.state.currentPrinterId;
        if(!currentPrinterId){
            app.alert('请选择打印机','error',2);
            return;
        }
        let data = this.state.printerData;
        for(let i=0;i<data.length;i++){
            if(data[i].printer_id==currentPrinterId){
                let type=this.props.type;
                if(type==1){
                    app.setData('printerOrderTaking',currentPrinterId);
                }else if(type==2){
                    app.setData('printerDistribution',currentPrinterId);
                }else if(type==3){
                    app.setData('printerCheckOrder',currentPrinterId);
                }
                this.setModalVisible1(false);
                let roleData=this.state.chooseData;
                this.props.choose(roleData,data[i].printer_ip);
            }
        }
    }
};
const ChooseOperates = Form.create()(ChooseOperate);

//汇总打印
//选择操作人
class PrintAll extends Component {
    constructor(props) {
        super(props);
        this.state = {
            editVisible: false,
            editConfirmLoading: false,
            roleData: [],
            type: this.props.type,
            chooseData: {},
            is_choose: -1,
            currentPrinterId:'',
            editVisible1: false,
            editConfirmLoading1: false,
            printerData:[]
        }
    };

    render() {
        return (
            <span>
                <Button style={{marginLeft: this.props.left}} type={'primary'}
                        onClick={() => this.setModalVisible(true)}>{this.props.buttonText}</Button>
                <span>
                    <Modal
                        maskClosable={true}
                        visible={this.state.editVisible}
                        editConfirmLoading={this.state.editConfirmLoading}
                        title="选择员工"
                        wrapClassName="vertical-center-modal"
                        width="600px"
                        onCancel={() => this.setModalVisible(false)}
                        footer={[
                            <Button key="back" type='default' onClick={() => {
                                this.setModalVisible(false)
                            }}>取消</Button>,
                            <Button key="submit" type="primary" onClick={() => {
                                this.clickOk()
                            }}>确定</Button>
                        ]}
                    >
                    <div className="clearfix">
                        {
                            this.state.roleData.map((item, index) => {
                                return (
                                    <span key={index}
                                          className={this.state.is_choose == index ? "roleItem1" : "roleItem"}
                                          onClick={() => this.chooseRole(index)}>
                                        {item.employee_name}
                                    </span>
                                )
                            })
                        }
                    </div>
                </Modal>

                    <Modal
                        maskClosable={true}
                        visible={this.state.editVisible1}
                        editConfirmLoading={this.state.editConfirmLoading1}
                        title="选择打印机"
                        wrapClassName="vertical-center-modal"
                        width="600px"
                        onCancel={() => this.setModalVisible1(false)}
                        footer={[
                            <Button key="back" type='default' onClick={() => {
                                this.setModalVisible1(false)
                            }}>取消</Button>,
                            <Button key="submit" type="primary" onClick={() => {
                                this.clickPrinterOk()
                            }}>确定</Button>
                        ]}
                    >
                    <div className="clearfix">
                        {
                            this.state.printerData.map((item, index) => {
                                return (
                                    <span key={index}
                                          className={item.printer_id == this.state.currentPrinterId ? "roleItem1" : "roleItem"}
                                          onClick={() => this.choosePrinter(index)}>
                                        {item.printer_name}
                                    </span>
                                )
                            })
                        }
                    </div>
                </Modal>
                </span>
            </span>
        )
    };

    componentDidMount(){
        let currentPrinterId='';
        let type=this.props.type;
        if(type==1){//待接单打印机ip
            currentPrinterId=app.getData('printerOrderTaking');
        }else if(type==2){//我来配货打印机ip
            currentPrinterId=app.getData('printerDistribution');
        }else if(type==3){//我来对货打印机ip
            currentPrinterId=app.getData('printerCheckOrder');
        }
        if(!currentPrinterId){
            currentPrinterId='';
        }
        this.setState({currentPrinterId:currentPrinterId});
        app.post(takeOutput.SEARCH_PRINTERLIST, {page: 1, size: 1000}).then((result) => {
            if (result.code === 1) {
                let printerData = result.data.dataSet;
                this.setState({printerData: printerData});
            } else {
                app.alert(result.msg, 'error', 3);
                this.setState({printerData: []});
            }
        });
    };

    /**
     * 显示和隐藏打印机弹框
     * @param visible
     */
    setModalVisible1(visible){
        this.setState({editVisible1:visible});
    };

    /**
     * 显示和隐藏选择员工弹框
     * @param visible
     */
    setModalVisible(visible) {
        if (visible) {
            let selectedRowKeys = this.props.selectedRowKeys;
            if (selectedRowKeys.length <= 0) {
                app.alert('请选择要打印的订单', 'error', 2);
                return;
            }
            app.post(employee.SEARCH_DUTYEMPLOYEE, {duty_type: this.props.duty_type}).then((result) => {
                if (result.code === 1) {
                    let roleData = result.data.dataSet;
                    this.setState({roleData});
                } else {
                    app.alert('没有查询到负责人数据', 'error', 2);
                    this.setState({roleData: []});
                }
            })
        }
        this.setState({
            editVisible: visible
        })
    };

    /**
     * 处理选择员工事件
     * @param index
     */
    chooseRole(index) {
        this.setState({is_choose: index});
        let chooseData = this.state.roleData[index];
        this.setState({chooseData: chooseData});
    };

    /**
     * 处理选择员工弹框确认事件
     */
    clickOk() {
        let data = this.state.chooseData;
        let employee_id = data.employee_id;
        if (employee_id == null || employee_id == undefined || employee_id.length <= 0) {
            app.alert("请选择操作人", 'error', 3);
            return;
        }
        this.setModalVisible1(true);
        this.setModalVisible(false);
        // this.props.choose(data);
        // this.setState({
        //     editVisible: false
        // })
    };

    /**
     * 处理选择打印机事件
     * @param index
     */
    choosePrinter(index){
        let data = this.state.printerData;
        let currentPrinterId = data[index].printer_id;
        this.setState({currentPrinterId: currentPrinterId});
    };

    /**
     * 处理打印机弹框确认事件
     */
    clickPrinterOk(){
        let currentPrinterId=this.state.currentPrinterId;
        if(!currentPrinterId){
            app.alert('请选择打印机','error',2);
            return;
        }
        let data = this.state.printerData;
        for(let i=0;i<data.length;i++){
            if(data[i].printer_id==currentPrinterId){
                let type=this.props.type;
                if(type==1){
                    app.setData('printerOrderTaking',currentPrinterId);
                }else if(type==2){
                    app.setData('printerDistribution',currentPrinterId);
                }else if(type==3){
                    app.setData('printerCheckOrder',currentPrinterId);
                }
                this.setModalVisible1(false);
                let roleData=this.state.chooseData;
                this.props.choose(roleData,data[i].printer_ip);
            }
        }
    }
};
const PrintAlls = Form.create()(PrintAll);


class InputStorage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
            shHelp: '',
            shStatus: '',
            shPerson: {
                role_id: '',
                role_name: ''
            },
            xhHelp: '',
            xhStatus: '',
            xhPerson: [],
            modalVisible: false
        }
    };

    formItemLayout = {
        labelCol: {span: 8},
        wrapperCol: {span: 16}
    };

    render() {
        return (
            <span>
                <Row>
                    <Button type='primary' onClick={() => this.setModalVisible(true)}>入库</Button>
                </Row>
                   <Modal
                       maskClosable={true}
                       title={'请输入'}
                       wrapClassName="vertical-center-modal"
                       width={'600px'}
                       visible={this.state.modalVisible}
                       confirmLoading={this.state.editConfirmLoading}
                       onOk={(e) => this.handleEditSubmit(e)}
                       onCancel={() => this.setModalVisible(false)}
                       footer={[
                           <Button key="back" type='default' onClick={() => this.setModalVisible(false)}>取消</Button>,
                           <Button key="submit" type='primary' onClick={() => this.clickOk()}>确定</Button>,
                       ]}
                   >
                       <Row>
                        <Col>
                            <Form className="login-form">
                                <FormItem label="收货人" help={this.state.shHelp}
                                          validateStatus={this.state.shStatus}
                                          required={true} {...this.formItemLayout}
                                >
                                    {this.state.shPerson.employee_name}
                                    <ChooseShs choose={(data) => this.handleChoose(data)}/>
                                </FormItem>
                                 <FormItem label="卸货人" help={this.state.xhHelp}
                                           validateStatus={this.state.xhStatus}
                                           required={true} {...this.formItemLayout}
                                 >
                                     {
                                         this.state.xhPerson.map((item, index) => {
                                             return (
                                                 <Tag key={index} closable
                                                      onClose={(e) => this.handleDelete(index, e)}>{item.employee_name}</Tag>
                                                 //<PersonItem key={index} role_name={item.role_name} index={index} handleDelete={(index)=>this.handleDelete(index)} />
                                             )
                                         })
                                     }
                                     <ChooseXhs choose={(data) => this.handleChooseMore(data)}/>
                                </FormItem>
                            </Form>
                        </Col>
                    </Row>
                   </Modal>
            </span>
        )
    };

    setModalVisible(visible) {
        this.setState({modalVisible: visible});
    };

    handleChoose(data) {
        console.log(data);
        this.setState({shPerson: data});
    };

    handleChooseMore(data) {
        console.log(data);
        this.setState({xhPerson: data});
    }

    clickOk() {
        let shPerson = this.state.shPerson;
        let xhPerson = this.state.xhPerson;
        if (shPerson.employee_id == null || shPerson.employee_id.length <= 0) {
            this.setState({
                shHelp: '请选择收货人',
                shStatus: 'error',
            });
            return;
        }
        if (xhPerson.length <= 0) {
            this.setState({
                xhHelp: '请选择卸货人',
                xhStatus: 'error',
            });
            return;
        }

        let role = [];
        role.push(JSON.stringify(shPerson));
        role.push(JSON.stringify(xhPerson));
        this.props.handleStorageDetail(JSON.stringify(role));
    };

    handleDelete(index, e) {
        e.preventDefault();
        let data = this.state.xhPerson;
        data.splice(index, 1);
        this.setState({xhPerson: data});
    }
}

const InputStorages = Form.create()(InputStorage);

//选择收货人
class ChooseSh extends Component {
    constructor(props) {
        super(props);
        this.state = {
            editVisible: false,
            editConfirmLoading: false,
            roleData: [],
            type: this.props.type,
            chooseData: {},
            is_choose: -1,
        }
    };

    render() {
        return (
            <span>
                <a style={{marginLeft: '15px'}} onClick={() => this.setModalVisible(true)}>选择</a>
                <Row>
                    <Modal
                        maskClosable={true}
                        visible={this.state.editVisible}
                        editConfirmLoading={this.state.editConfirmLoading}
                        title="选择员工"
                        wrapClassName="vertical-center-modal"
                        width="600px"
                        onCancel={() => this.setModalVisible(false)}
                        footer={[
                            <Button key="back" type='default' onClick={() => {
                                this.setModalVisible(false)
                            }}>取消</Button>,
                            <Button key="submit" type="primary" onClick={() => {
                                this.clickOk()
                            }}>确定</Button>
                        ]}
                    >
                    <div className="clearfix">
                        {
                            this.state.roleData.map((item, index) => {
                                return (
                                    <span key={index}
                                          className={this.state.is_choose == index ? "roleItem1" : "roleItem"}
                                          onClick={() => this.chooseRole(index)}>
                                        {item.employee_name}
                                    </span>
                                )
                            })
                        }
                    </div>
                </Modal>
                </Row>
            </span>
        )
    };

    setModalVisible(visible) {
        if (visible) {
            this.handleGetEmployee();
        }
        this.setState({
            editVisible: visible
        })
    };

    handleGetEmployee() {
        app.post(employee.SEARCH_DUTYEMPLOYEE, {duty_type: '4'}).then((result) => {
            if (result.code === 1) {
                let roleData = result.data.dataSet;
                let data = [];
                for (let i = 0; i < roleData.length; i++) {
                    let item = {};
                    item.employee_id = roleData[i].employee_id;
                    item.employee_name = roleData[i].employee_name;
                    data.push(item);
                }
                this.setState({roleData: data});
            } else {
                this.setState({roleData: []})
            }
        })
    }

    chooseRole(index) {
        this.setState({is_choose: index});
        let chooseData = this.state.roleData[index];
        this.setState({chooseData: chooseData})
    }

    clickOk() {
        let data = this.state.chooseData;
        this.props.choose(data);
        this.setState({
            editVisible: false
        })
    }
};
const ChooseShs = Form.create()(ChooseSh);

//选择卸货人
class ChooseXh extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
            editVisible: false,
            editConfirmLoading: false,
            roleData: [],
            type: this.props.type,
            chooseData: []
        }
    };

    render() {
        return (
            <span>
                <Button style={{marginLeft: '15px'}} type="default" size="small"
                        onClick={() => this.setModalVisible(true)}>
                    <Icon type="plus" style={{fontSize: 12}}/>
                </Button>
                <Row>
                    <Modal
                        maskClosable={true}
                        visible={this.state.editVisible}
                        editConfirmLoading={this.state.editConfirmLoading}
                        title="选择员工"
                        wrapClassName="vertical-center-modal"
                        width="600px"
                        onCancel={() => this.setModalVisible(false)}
                        footer={[
                            <Button key="back" type='default' onClick={() => {
                                this.setModalVisible(false)
                            }}>取消</Button>,
                            <Button key="submit" type="primary" onClick={() => {
                                this.clickOk()
                            }}>确定</Button>
                        ]}
                    >
                    <div className="clearfix">
                        {
                            this.state.roleData.map((item, index) => {
                                return (
                                    <span key={index} className={item.is_choose == true ? "roleItem1" : "roleItem"}
                                          onClick={() => this.chooseRole(index)}>
                                        {item.employee_name}
                                    </span>
                                )
                            })
                        }
                    </div>
                </Modal>
                </Row>
            </span>
        )
    };

    setModalVisible(visible) {
        if (visible) {
            this.handleGetEmployee();
        }
        this.setState({
            editVisible: visible
        })
    };

    handleGetEmployee() {
        app.post(employee.SEARCH_DUTYEMPLOYEE, {duty_type: '4'}).then((result) => {
            if (result.code === 1) {
                let roleData = result.data.dataSet;
                let data = [];
                for (let i = 0; i < roleData.length; i++) {
                    let item = {};
                    item.employee_id = roleData[i].employee_id;
                    item.employee_name = roleData[i].employee_name;
                    data.push(item);
                }
                this.setState({roleData: data});
            } else {
                this.setState({roleData: []})
            }
        })
    }

    chooseRole(index) {
        let data = this.state.roleData;
        let is_choose = !data[index].is_choose;
        data[index].is_choose = is_choose;
        this.setState({roleData: data});
    }

    clickOk() {
        let data = this.state.roleData;
        let newData = [];
        for (let i = 0; i < data.length; i++) {
            if (data[i].is_choose == true) {
                newData.push(data[i]);
            }
        }
        this.props.choose(newData);
        this.setState({editVisible: false});
    }
};
const ChooseXhs = Form.create()(ChooseXh);

class PersonItem extends Component {
    constructor(props) {
        super(props);
        this.state = {}
    };

    render() {
        return (
            <span style={{
                backgroundColor: '#f5f5f5',
                border: '1px solid #d9d9d9',
                borderRadius: '1px',
                padding: '1px 1px 1px 3px',
                marginRight: '5px',
                fontSize: '12px'
            }}>
                {this.props.role_name}<Icon style={{marginLeft: '5px'}} type="close"
                                            onClick={() => this.handleDelete()}></Icon>
            </span>
        )
    };

    handleDelete() {
        this.props.handleDelete(this.props.index);
    }
}


class CheckBtn extends Component {
    constructor(props) {
        super(props);
        this.state = {
            editVisible: false,
            editConfirmLoading: false,
            editVisible1: false,
            editConfirmLoading1: false,
        };
    };

    formItemLayout = {
        labelCol: {span: 8},
        wrapperCol: {span: 12},
    };

    render() {
        const {getFieldDecorator} = this.props.form;
        return (
            <span>
                <Button style={{marginLeft: '10px', marginTop: '5px'}} type="primary"
                        onClick={() => this.handleCancel(true)}>完成</Button>
                <Modal
                    maskClosable={true}
                    visible={this.state.editVisible}
                    editConfirmLoading={this.state.editConfirmLoading}
                    title="请选择"
                    wrapClassName="vertical-center-modal"
                    width="400px"
                    onCancel={() => this.setModalVisible(false)}
                    footer={[
                        <Button key="gai" type='primary' onClick={() => {
                            this.handleError("1")
                        }}>待改单</Button>,
                        <Button key="pei" type='primary' onClick={() => {
                            this.handleError("2")
                        }}>重新配货</Button>
                    ]}
                >
                    检测到该订单有异常，继续出货，还是重新配货？
                </Modal>

                <Modal
                    maskClosable={true}
                    visible={this.state.editVisible1}
                    editConfirmLoading={this.state.editConfirmLoading1}
                    title="请输入"
                    wrapClassName="vertical-center-modal"
                    width="400px"
                    onCancel={() => this.handleCancel()}
                    footer={[
                        <Button key="cancel" onClick={() => {
                            this.handleCancel(false)
                        }}>取消</Button>,
                        <Button key="confirm" type='primary' onClick={() => {
                            this.handleConfirm()
                        }}>确定</Button>
                    ]}
                >
                     <Row>
                        <Form className="login-form">
                            <FormItem label="件数" {...this.formItemLayout}>
                                {
                                    getFieldDecorator('output_real_package', {
                                        rules: [{required: true, message: '请输入件数'}]
                                    })(
                                        <Input placeholder="请输入"/>
                                    )
                                }
                            </FormItem>
                             <FormItem label="散件数" {...this.formItemLayout}>
                                {
                                    getFieldDecorator('output_real_parts', {
                                        rules: [{required: true, message: '请输入散件数'}]
                                    })(
                                        <Input placeholder="请输入"/>
                                    )
                                }
                            </FormItem>
                        </Form>
                    </Row>
                </Modal>
            </span>
        )
    };

    /**
     * 正常时显示与隐藏弹框
     * @param visible
     */
    setModalVisible1(visible) {
        if (visible) {
            let output_single = this.props.output_single;
            if (output_single && Number(output_single) > 0) {
                output_single = 1;
            } else {
                output_single = 0;
            }
            let data = {
                output_real_package: this.props.output_package,
                output_real_parts: output_single
            };
            this.props.form.setFieldsValue(data);
        }
        this.setState({editVisible1: visible});
    };

    /**
     * 异常时显示与隐藏弹框
     * @param visible
     */
    setModalVisible(visible) {
        this.setState({editVisible: visible});
    };

    /**
     * 处理待改单或重新配货
     * @param type
     */
    handleError(type) {
        let data = {
            output_id: this.props.output_id,
            type: type
        };
        app.post(takeOutput.FINISH_MATCHOUTPUT, data).then((result) => {
            if (result.code === 1) {
                app.alert(result.msg, 'success', 3);
                this.props.handleRefresh();
            } else {
                app.alert(result.msg, 'error', 3);
            }
        });
        this.handleCancel(false);
    }

    /**
     * 根据订单状态显示不同的弹框
     * @param visible
     */
    handleCancel(visible) {
        let status = this.props.status;
        if (status == 2) {
            this.setModalVisible1(visible);
        } else if (status == 1) {
            this.setModalVisible(visible);
        }
    };

    /**
     * 订单正常时修改订单件数和散件数
     */
    handleConfirm() {
        let _this = this;
        this.props.form.validateFields((error, values) => {
            if (!error) {
                let data = {
                    output_id: _this.props.output_id,
                    type: "0",
                    output_real_package: values.output_real_package,
                    output_real_parts: values.output_real_parts
                };
                app.post(takeOutput.FINISH_MATCHOUTPUT, data).then((result) => {
                    if (result.code === 1) {
                        app.alert(result.msg, 'success', 3);
                        _this.props.handleRefresh();
                    } else {
                        app.alert(result.msg, 'error', 3);
                    }
                });
                _this.handleCancel(false);
            }
        })
    }
}

const CheckBtns = Form.create()(CheckBtn);

class CheckAgain extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
            editVisible: false,
            editConfirmLoading: false,
        };
    };

    formItemLayout = {
        labelCol: {span: 8},
        wrapperCol: {span: 12},
    };

    render() {
        const {getFieldDecorator} = this.props.form;
        return (
            <span>
                <Button type="primary" style={{marginLeft: '10px'}}
                        onClick={() => this.setModalVisible(true)}>重新配货</Button>
                <Modal
                    maskClosable={true}
                    visible={this.state.editVisible}
                    editConfirmLoading={this.state.editConfirmLoading}
                    title="请输入"
                    wrapClassName="vertical-center-modal"
                    width="400px"
                    onCancel={() => this.setModalVisible(false)}
                    footer={[
                        <Button key="back" type='default' onClick={() => {
                            this.setModalVisible(false)
                        }}>取消</Button>,
                        <Button key="submit" type="primary" onClick={() => {
                            this.clickOk()
                        }}>确定</Button>
                    ]}
                >
                    <Row>
                        <Form className="login-form">
                            <FormItem label="散数" {...this.formItemLayout}>
                                {
                                    getFieldDecorator('s_s')(
                                        <Input placeholder="请输入"/>
                                    )
                                }
                            </FormItem>
                            <FormItem label="件数" {...this.formItemLayout}>
                                {
                                    getFieldDecorator('j_s')(
                                        <Input placeholder="请输入"/>
                                    )
                                }
                            </FormItem>
                            <FormItem label="应收款" {...this.formItemLayout}>
                                {
                                    getFieldDecorator('money')(
                                        <Input placeholder="请输入"/>
                                    )
                                }
                            </FormItem>
                        </Form>
                    </Row>
                </Modal>
            </span>
        )
    };

    setModalVisible(visible) {
        this.setState({editVisible: visible});
    };

    clickOk() {
        let order_number = this.props.order_number;
        console.log(order_number);
    }
}

const CheckAgains = Form.create()(CheckAgain);

class FinishStorage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
            editVisible: false,
            editConfirmLoading: false,
        };
    };

    formItemLayout = {
        labelCol: {span: 8},
        wrapperCol: {span: 12},
    };

    render() {
        const {getFieldDecorator} = this.props.form;
        return (
            <span>
                <Button onClick={() => this.setModalVisible(true)} type="primary"
                        style={{float: 'right', marginTop: '18px', marginRight: '50px'}}>完成</Button>
                <Modal
                    maskClosable={true}
                    visible={this.state.editVisible}
                    editConfirmLoading={this.state.editConfirmLoading}
                    title="请输入"
                    wrapClassName="vertical-center-modal"
                    width="400px"
                    onCancel={() => this.setModalVisible(false)}
                    footer={[
                        <Button key="back" type='default' onClick={() => {
                            this.setModalVisible(false)
                        }}>取消</Button>,
                        <Button key="submit" type="primary" onClick={() => {
                            this.clickOk()
                        }}>确定</Button>
                    ]}
                >
                    <Row>
                        <Form className="login-form">
                            <FormItem label="实际件数" {...this.formItemLayout}>
                                {
                                    getFieldDecorator('storage_real_package', {
                                        rules: [{required: true, message: '请输入实际件数'}]
                                    })(
                                        <Input placeholder="请输入"/>
                                    )
                                }
                            </FormItem>
                            <FormItem label="实际散包数" {...this.formItemLayout}>
                                {
                                    getFieldDecorator('storage_real_single', {
                                        rules: [{required: true, message: '请输入实际散包数'}]
                                    })(
                                        <Input placeholder="请输入"/>
                                    )
                                }
                            </FormItem>
                            <FormItem label="实际金额" {...this.formItemLayout}>
                                {
                                    getFieldDecorator('storage_real_money', {
                                        rules: [{required: true, message: '请输入实际金额'}]
                                    })(
                                        <Input placeholder="请输入"/>
                                    )
                                }
                            </FormItem>
                        </Form>
                    </Row>
                </Modal>
            </span>
        )
    };

    /**
     * 显示和隐藏弹框
     * @param visible
     */
    setModalVisible(visible) {
        if (visible) {
            let values = {};
            values.storage_real_money = this.props.storage_money;
            let data = this.props.data;
            let real_single = 0;
            let real_package = 0;
            for (let i = 0; i < data.length; i++) {
                real_package += Number(data[i].storage_detail_real_package);
                real_single += Number(data[i].storage_detail_real_single);
            }
            values.storage_real_package = real_package;
            values.storage_real_single = real_single;
            this.props.form.setFieldsValue(values);
        }
        this.setState({editVisible: visible});
    };

    /**
     * 处理编辑事件
     */
    clickOk() {
        this.props.form.validateFields((error, values) => {
            if (!error) {
                this.props.handleFinish(values);
            }
        })
    };
}

const FinishStorages = Form.create()(FinishStorage);

class CheckBtnStart extends Component {
    constructor(props) {
        super(props);
        this.state = {
            editVisible1: false,
            editConfirmLoading1: false,
            roleData: [],
            type: this.props.type,
            chooseData: {},
            is_choose: -1,
        };
    };

    render() {
        return (
            <span>
                <Button onClick={() => this.setModalVisible1(true)} style={{marginLeft: '10px', marginTop: '5px'}}
                        type="primary">对单</Button>
                <Modal
                    maskClosable={true}
                    visible={this.state.editVisible1}
                    editConfirmLoading={this.state.editConfirmLoading1}
                    title="选择员工"
                    wrapClassName="vertical-center-modal"
                    width="600px"
                    onCancel={() => this.setModalVisible1(false)}
                    footer={[
                        <Button key="back" type='default' onClick={() => {
                            this.setModalVisible1(false)
                        }}>取消</Button>,
                        <Button key="submit" type="primary" onClick={() => {
                            this.clickOk1()
                        }}>确定</Button>
                    ]}
                >
                    <div className="clearfix">
                        {
                            this.state.roleData.map((item, index) => {
                                return (
                                    <span key={index}
                                          className={this.state.is_choose == index ? "roleItem1" : "roleItem"}
                                          onClick={() => this.chooseRole(index)}>
                                        {item.employee_name}
                                    </span>
                                )
                            })
                        }
                    </div>
                </Modal>
            </span>
        )
    };

    /**
     * 显示隐藏操作人选择框
     * @param visible
     */
    setModalVisible1(visible) {
        if (visible) {
            app.post(employee.SEARCH_DUTYEMPLOYEE, {duty_type: '2'}).then((result) => {
                if (result.code === 1) {
                    let roleData = result.data.dataSet;
                    this.setState({roleData});
                }
            });
        }
        this.setState({editVisible1: visible});
    };

    /**
     * 选择操作人
     * @param index
     */
    chooseRole(index) {
        this.setState({is_choose: index});
        let chooseData = this.state.roleData[index];
        this.setState({chooseData: chooseData});
    };

    /**
     * 处理完成选择事件
     */
    clickOk1() {
        let data = this.state.chooseData;
        let employee_id = data.employee_id;
        if (employee_id == null || employee_id == undefined || employee_id.length <= 0) {
            app.alert("请选择操作人", 'error', 3);
            return;
        }
        app.setData('employee_id', employee_id);
        this.setModalVisible1(false);
        this.props.handleCheckOrder();
    };
}

const CheckBtnStarts = Form.create()(CheckBtnStart);

//选择打印机
class ChoosePrinter extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
            editVisible: false,
            editConfirmLoading: false,
            roleData: [],
            chooseData: [],
            confirmLoading: false,
            currentPrinterId:''
        }
    };

    formItemLayout = {
        labelCol: {span: 8},
        wrapperCol: {span: 12},
    };

    render() {
        return (
            <span>
                <Button type={'primary'} onClick={() => this.setModalVisible(true)}>打印</Button>
                <span>
                    <Modal
                        maskClosable={true}
                        visible={this.state.editVisible}
                        editConfirmLoading={this.state.editConfirmLoading}
                        confirmLoading={this.state.confirmLoading}
                        title="选择打印机"
                        wrapClassName="vertical-center-modal"
                        width="600px"
                        onCancel={() => this.setModalVisible(false)}
                        footer={[
                            <Button key="back" type='default' onClick={() => {
                                this.setModalVisible(false)
                            }}>取消</Button>,
                            <Button key="submit" type="primary" onClick={() => {
                                this.clickOk()
                            }}>确定</Button>
                        ]}
                    >
                    <div className="clearfix">
                        {
                            this.state.roleData.map((item, index) => {
                                return (
                                    <span key={index} className={item.printer_id == this.state.currentPrinterId ? "roleItem1" : "roleItem"}
                                          onClick={() => this.chooseRole(index)}>
                                        {item.printer_name}
                                    </span>
                                )
                            })
                        }
                    </div>
                </Modal>
                </span>
            </span>
        )
    };

    componentDidMount() {
        let currentPrinterId='';
        let type=this.props.type;
        if(type==1){//待接单打印机ip
            currentPrinterId=app.getData('printerOrderTaking');
        }else if(type==2){//我来配货打印机ip
            currentPrinterId=app.getData('printerDistribution');
        }else if(type==3){//我来对货打印机ip
            currentPrinterId=app.getData('printerCheckOrder');
        }
        if(!currentPrinterId){
            currentPrinterId='';
        }
        this.setState({currentPrinterId:currentPrinterId});
        this.handleGetPrinterData();
    }

    /**
     * 获取打印机列表
     */
    handleGetPrinterData() {
        app.post(takeOutput.SEARCH_PRINTERLIST, {page: 1, size: 1000}).then((result) => {
            if (result.code === 1) {
                let roleData = result.data.dataSet;
                this.setState({roleData: roleData});
            } else {
                app.alert(result.msg, 'error', 3);
                this.setState({roleData: []});
            }
        });
    }

    /**
     * 显示和隐藏弹框
     * @param visible
     */
    setModalVisible(visible) {
        this.setState({
            editVisible: visible
        });
    };

    /**
     * 选择打印机
     * @param index
     */
    chooseRole(index) {
        let data = this.state.roleData;
        let currentPrinterId = data[index].printer_id;
        this.setState({currentPrinterId: currentPrinterId});
    }

    /**
     * 处理确认事件
     */
    clickOk() {
        let currentPrinterId=this.state.currentPrinterId;
        if(!currentPrinterId){
            app.alert('请选择打印机','error',2);
            return;
        }
        let data = this.state.roleData;
        for(let i=0;i<data.length;i++){
            if(data[i].printer_id==currentPrinterId){
                let type=this.props.type;
                if(type==1){
                    app.setData('printerOrderTaking',currentPrinterId);
                }else if(type==2){
                    app.setData('printerDistribution',currentPrinterId);
                }else if(type==3){
                    app.setData('printerCheckOrder',currentPrinterId);
                }
                this.setModalVisible(false);
                this.props.handlePrintCar(data[i].printer_ip);
            }
        }
    }
};
const ChoosePrinters = Form.create()(ChoosePrinter);

export {
    InputStorages,
    CheckBtns,
    ChooseOperates,
    FinishStorages,
    CheckBtnStarts,
    PrintAlls,
    ChoosePrinters
}